﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Linq;
using M7;

namespace S7
{
	/// <summary>
	/// Interaction logic for News.xaml
	/// </summary>
	public partial class News : Window
	{
		public News()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Info.News = tbNews.Text;
            Properties.Settings.Default.News = tbNews.Text;
            Properties.Settings.Default.Save();
            var cons = from tb in Info.window.wrpLiveView.Children.OfType<TableControl>()
                       where tb.Connection != null
                       select tb.Connection;
            foreach (var con in cons)
            {
                Msg SendMsg = new Msg();
                SendMsg.enumMethod = MessageBoxButton.OKCancel;
                SendMsg.IP = con.current.IP;
                SendMsg.port = con.current.Port;
                SendMsg.obj = Info.News;
                Info.server.SendingQueue.Enqueue(SendMsg);
            }
            Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            tbNews.Text = Info.News;
        }
	}
}